using System.Linq;
using NUnit.Framework;

namespace Solver
{
	/// <summary>
	/// Find the sum of the digits in the number 100!
	/// </summary>
	public class Problem020 : SelfChecker, IProblem
	{
		public int Id
		{
			get { return 20; }
		}

		public string Solve()
		{
			return Solve(99).ToString();
		}

		[Test]
		public override void Check()
		{
			Assert.AreEqual(9, Solve(6));
			Assert.AreEqual(648, Solve(99));
			Assert.AreEqual(648, Solve(100));
		}

		private static int Solve(int param)
		{
			var fac = new Number(1);
			for (int i = 2; i <= param; i++)
				fac = fac.Multiply(new Number(i));
			return fac.Digits().Sum();
		}
	}
}